#ifndef __LUOO_TCP_SEND_BUFFER_HPP__
#define __LUOO_TCP_SEND_BUFFER_HPP__

#include <boost/asio.hpp>
#include <boost/cast.hpp>
#include <boost/thread.hpp>

namespace luoo
{
	class tcp_send_buffer
	{
	public:
		void append(const void* data_ptr, luoo::uint32 data_len)
		{
			boost::mutex::scoped_lock lock(mutex_);
			send_buffer_.sputn(static_cast<const char*>(data_ptr), boost::numeric_cast<std::streamsize>(data_len));
		}

		boost::asio::streambuf::const_buffers_type data()
		{
			boost::mutex::scoped_lock lock(mutex_);
			return send_buffer_.data();
		}
		
		std::size_t size()
		{
			boost::mutex::scoped_lock lock(mutex_);
			return send_buffer_.size();
		}

		void consume(luoo::uint32 n)
		{
			boost::mutex::scoped_lock lock(mutex_);
			send_buffer_.consume(n);
		}

	private:
		boost::mutex mutex_;
		boost::asio::streambuf send_buffer_;
	};
}//namespace luoo

#endif//__LUOO_TCP_SEND_BUFFER_HPP__